<?php

namespace App\Models\Rbac;

use App\Models\Common\CommonModel;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;

class Permission extends CommonModel {

    protected $table = 'guard_permission';

    public function moreChildren() {
        return $this->hasMany(Permission::class,'pid','id')->orderBy('sort');
    }

    public function children() {
        return $this->moreChildren()->with(['children']);
    }

    public function getLst(array $conditions = []): Builder {
        $records = parent::getLst($conditions); // TODO: Change the autogenerated stub
         if(isset($conditions['pid'])){
             $records = $records->where('pid',$conditions['pid']);
         }
        return $records;
    }

    public static function getMaxSort() {
        return self::selectRaw('MAX(sort) as value')->get()->first()->value??0;
    }




}
